package my.study.c.consul.consumer.app.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class IOUtil {

    public static byte[] getBytes(InputStream in) throws IOException {
        int n = in.available();
        byte[] bytes = new byte[n];
        in.read(bytes, 0, n);
        return bytes;
    }

    public static String getString(InputStream in) throws IOException {
        return new String(IOUtil.getBytes(in), StandardCharsets.UTF_8);
    }

    public static String getString(InputStream in, Charset charset) throws IOException {
        return new String(IOUtil.getBytes(in), charset);
    }
}
